import DecoratorApplicationContext from "@framework/context/DecoratorApplicationContext";
import StrUtils from "@framework/util/StrUtils";

/**
 * Koa工具类
 */
class KoaBootUtil {

    /**
     * 全局上下文
     * @private
     */
    private static context: DecoratorApplicationContext;

    /**
     * 获取Bean实例
     * @param beanName
     */
    public static getBean(beanName: string): Object | undefined {
        if (StrUtils.isBlank(beanName)) {
            return undefined;
        }
        return KoaBootUtil.context.getBean(beanName);
    }

    /**
     * 设置全局上下文
     * @param context
     */
    public static setContext(context: DecoratorApplicationContext) {
        KoaBootUtil.context = context;
    }
}

export default KoaBootUtil;